<?php
session_start();
require_once('configs/common.php');
require_once('models/Auth.class.php');	
require_once("configs/db_connect.php");
require_once("models/MyAccount.class.php");

$code=safe_var($_GET['code']);

if (Auth::isCheckSuccess())
{
	 header('Location: my_account.php');
}
else
{
	$recovery_data=MyAccount::getRecoveryCode($code);
	
	
	if (!$recovery_data)
	{
		 $recovery['wrong_code']=true;
	}
	else
	{
		$_SESSION['email']= $recovery_data[0]['email'];
		$_SESSION['user_id']= $recovery_data[0]['users_id'];
		
		if ($recovery_data[0]['confirm_status']=='yes')
		{
			 $recovery['is_confirmed']=true;
			 $recovery['confirm_data']=$recovery_data[0]['confirm_date'];
			 
		}
		else
		{
			 MyAccount::updateRecoveryTable($code);		 		 
		}
	}	

	 try 
	{					
		 $template = $twig->loadTemplate('recovery_password.html');			 
		 $data=Translate::getPageKeys(KEYS_FILE."my_account.ini"); 
		 $data['recovery']=$recovery;	
			 
		 echo $template->render($data);		
  
	} 
	catch (Exception $e) 
	{
		 die ('ERROR: ' . $e->getMessage());
	}
}